#include "liblut/gui/wx/ColorDialog.h"

#include <wx/button.h>
#include "wx/sizer.h"
#include <wx/stattext.h>
#include <wx/valgen.h>


/*------------------------------------------------------------------------------------------*/
/*					MyData: les donnÃ©es qui doivent Ãªtre transfÃ©rÃ©es						*/
/*				lors du choix de la couleur dans la boite de dialogque MyDialog				*/
/*------------------------------------------------------------------------------------------*/

MyData::MyData()
{
    m_rouge_state = 125;
    m_vert_state  = 125;
    m_bleu_state = 125;
    m_teinte_state = 180;
    m_saturation_state = 125;
    m_luminance_state = 125;
}

ColorDialog::ColorDialog(MyData* mydata, wxWindow *parent, const wxString& title,
        const wxPoint& pos, const wxSize& size, const long WXUNUSED(style) ) :
        wxDialog(parent, ID_DIALOG_COULEUR, title, pos, size, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
{
    g_data = mydata;
    //sizer global qui contient tous les autres sizers
    wxBoxSizer *globalSizerDialog = new wxBoxSizer( wxVERTICAL );
    SetSizer( globalSizerDialog );

    wxBoxSizer *sizerDialogDroit = new wxBoxSizer( wxHORIZONTAL );
    globalSizerDialog->Add(sizerDialogDroit,
                            0,
                            wxALIGN_LEFT |wxADJUST_MINSIZE);

    wxStaticText *checkboxrvb = new wxStaticText(this,
                                                    wxID_ANY,
                                                    _T("RVB"),
                                                    wxDefaultPosition,
                                                    wxSize(250,15),
                                                    0,
                                                    _T("checkBox"));
    wxStaticText *checkboxtsl = new wxStaticText(this,
                                                    wxID_ANY,
                                                    _T("TSL"),
                                                    wxDefaultPosition,
                                                    wxSize(150,15),
                                                    0,
                                                    _T("checkBox"));
    sizerDialogDroit->Add(checkboxrvb,
                            0,
                            wxALIGN_LEFT |wxTOP|wxLEFT,
                            20 );
    sizerDialogDroit->Add(checkboxtsl,
                            0,
                            wxALIGN_RIGHT |wxTOP,
                            20 );
    wxFlexGridSizer *gridSizerDialog = new wxFlexGridSizer(3, 4, 7, 25);

    globalSizerDialog->Add(gridSizerDialog,
                            0,
                            wxALIGN_LEFT |wxADJUST_MINSIZE|wxALL,
                            10);

    wxStaticText *Texterouge = new wxStaticText(this,
                                                -1,
                                                _T("R"),
                                                wxDefaultPosition,
                                                wxSize(10,15),
                                                0,
                                                _T("Texterouge"));
    //le slider permettant de choisir la couleur rouge
    rouge = new wxSlider( this,
                        ID_DIALOG_ROUGE,
                        0,
                        0,
                        255,
                        wxDefaultPosition,
                        wxSize(150,wxDefaultCoord),
                        wxSL_AUTOTICKS | wxSL_LABELS,
                        wxGenericValidator(&(g_data->m_rouge_state)),
                        _T("rouge"));
    rouge->SetValue(125);
    wxStaticText *TexteTeinte = new wxStaticText(this,
                                                    -1,
                                                    _T("T"),
                                                    wxDefaultPosition,
                                                    wxSize(10,15),
                                                    0,
                                                    _T("TexteTeinte"));
    //le slider permettant de choisir la teinte
    teinte = new wxSlider( this,
                            ID_DIALOG_TEINTE,
                            0,
                            0,
                            359,
                            wxDefaultPosition,
                            wxSize(150,wxDefaultCoord),
                            wxSL_AUTOTICKS | wxSL_LABELS,
                            wxGenericValidator(&(g_data->m_teinte_state)),
                            _T("teinte"));
    teinte->SetValue(180);
    wxStaticText *Textevert = new wxStaticText(this,
                                                -1,
                                                _T("V"),
                                                wxDefaultPosition,
                                                wxSize(10,15),
                                                0,
                                                _T("transparence"));
    //le slider permettant de choisir la couleur verte
    vert = new wxSlider( this,
                        ID_DIALOG_VERT,
                        0,
                        0,
                        255,
                        wxDefaultPosition,
                        wxSize(150,wxDefaultCoord),
                        wxSL_AUTOTICKS | wxSL_LABELS,
                        wxGenericValidator(&(g_data->m_vert_state)),
                        _T("vert"));
    vert->SetValue(125);
    wxStaticText *TexteSaturation = new wxStaticText(this,
                                                        -1,
                                                        _T("S"),
                                                        wxDefaultPosition,
                                                        wxSize(10,15),
                                                        0,
                                                        _T("TexteSaturation"));
    //le slider permettant de choisir la saturation
    saturation = new wxSlider( this,
                                ID_DIALOG_SATURATION,
                                0,
                                0,
                                255,
                                wxDefaultPosition,
                                wxSize(150,wxDefaultCoord),
                                wxSL_AUTOTICKS | wxSL_LABELS,
                                wxGenericValidator(&(g_data->m_saturation_state)),
                                _T("saturation"));
    saturation->SetValue(125);
    wxStaticText *Textebleu = new wxStaticText(this,
                                                -1,
                                                _T("B"),
                                                wxDefaultPosition,
                                                wxSize(10,15),
                                                0,
                                                _T("transparence"));
    //le slider permettant de choisir la couleur bleue
    bleu = new wxSlider( this,
                        ID_DIALOG_BLEU,
                        0,
                        0,
                        255,
                        wxDefaultPosition,
                        wxSize(150,wxDefaultCoord),
                        wxSL_AUTOTICKS | wxSL_LABELS,
                        wxGenericValidator(&(g_data->m_bleu_state)),
                        _T("bleu"));
    bleu->SetValue(125);
    wxStaticText *TexteLuminance = new wxStaticText(this,
                                                    -1,
                                                    _T("L"),
                                                    wxDefaultPosition,
                                                    wxSize(10,15),
                                                    0,
                                                    _T("TexteLuminance"));
    //le slider permettant de choisir la luminance
    luminance = new wxSlider( this,
                                ID_DIALOG_LUMINANCE,
                                0,
                                0,
                                255,
                                wxDefaultPosition,
                                wxSize(150,wxDefaultCoord),
                                wxSL_AUTOTICKS | wxSL_LABELS,
                                wxGenericValidator(&(g_data->m_luminance_state)),
                                _T("luminance"));
    luminance->SetValue(125);


    gridSizerDialog->Add(Texterouge,
                            0,
                            wxTOP|wxALIGN_LEFT |wxADJUST_MINSIZE,
                            15);
    gridSizerDialog->Add(rouge,
                            0,
                            wxALIGN_LEFT |wxADJUST_MINSIZE);

    gridSizerDialog->Add(TexteTeinte,
                            0,
                            wxTOP|wxALIGN_LEFT |wxADJUST_MINSIZE,
                            15);
    gridSizerDialog->Add(teinte,
                        0,
                        wxALIGN_LEFT |wxADJUST_MINSIZE);

    gridSizerDialog->Add(Textevert,
                            0,
                            wxTOP|wxALIGN_LEFT |wxADJUST_MINSIZE,
                            15);
    gridSizerDialog->Add(vert,
                            0,
                            wxALIGN_LEFT |wxADJUST_MINSIZE);


    gridSizerDialog->Add(TexteSaturation,
                            0,
                            wxTOP|wxALIGN_LEFT |wxADJUST_MINSIZE,
                            15);
    gridSizerDialog->Add(saturation,
                            0,
                            wxALIGN_LEFT |wxADJUST_MINSIZE);

    gridSizerDialog->Add(Textebleu,
                            0,
                            wxTOP|wxALIGN_LEFT |wxADJUST_MINSIZE,
                            15);
    gridSizerDialog->Add(bleu,
                            0,
                            wxALIGN_LEFT |wxADJUST_MINSIZE);

    gridSizerDialog->Add(TexteLuminance,
                            0,
                            wxTOP|wxALIGN_LEFT |wxADJUST_MINSIZE,
                            15);
    gridSizerDialog->Add(luminance,
                            0,
                            wxALIGN_LEFT |wxADJUST_MINSIZE);

    wxBoxSizer *sizerDialogValidate = new wxBoxSizer( wxHORIZONTAL );
        globalSizerDialog->Add(sizerDialogValidate,
                                0,
                                wxALIGN_RIGHT |wxADJUST_MINSIZE);
    wxButton *boutonOK = new wxButton(this,
                                        wxID_OK,
                                        _T("OK"),
                                        wxDefaultPosition,
                                        wxSize(60,25),
                                        0,
                                        wxDefaultValidator,
                                        _T("OK"));
    sizerDialogValidate->Add(boutonOK,
                                0,
                                wxALIGN_RIGHT |wxADJUST_MINSIZE|wxRIGHT|wxBOTTOM,
                                15);
    globalSizerDialog->SetSizeHints(this);

    if(g_data->m_systCouleur == 0)
    {
        teinte->Disable();
        saturation->Disable();
        luminance->Disable();
    }
    else if(g_data->m_systCouleur == 1)
    {
        rouge->Disable();
        vert->Disable();
        bleu->Disable();
    }
}

/*---------------------------------------------------------------------------*/
/*  Permet de transmettre les couleurs dÃ©finies Ã  la fenetre principale	 	 */
/*---------------------------------------------------------------------------*/
bool ColorDialog::TransferDataToWindow()
{
    bool r = wxDialog::TransferDataToWindow();
    return r;
}

/*----------------------------------------------------------------------------------*/
/*  Permet de transfÃ©rer les donnÃ©es de la fenetre principale Ã  la boite de dialogue*/
/* 	 			notamment le systÃšme de couleur choisi	 							*/
/*----------------------------------------------------------------------------------*/
bool ColorDialog::TransferDataFromWindow()
{
    bool d = wxDialog::TransferDataFromWindow();
    return d;
}
